package compare;

import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.imgcodecs.Imgcodecs;
import xiugai.other.OpencvUtil;

import java.util.List;

/**
 * 国徽
 */
public class MatchShapes_GuoHui {

    public static void main(String[] args) {
        String path="C:/Users/admin/Desktop/shengfenzheng/OIP.jpg";
        Mat mat= Imgcodecs.imread(path);
        List<MatOfPoint> fiset = houghLinesP(mat);
        String path2="C:/Users/admin/Desktop/cut/u=326162972,2676140621&fm=26&gp=0.jpg";
        Mat mat2= Imgcodecs.imread(path2);
        List<MatOfPoint> second = houghLinesP(mat2);
    }

    public static List<MatOfPoint> houghLinesP(Mat mat) {
        //灰度
//        mat= OpencvUtil.gray(mat);
        //二值化
        mat = OpencvUtil.binary(mat);
        Imgcodecs.imwrite("C:/Users/admin/Desktop/cut/test_all_erzhihua.jpg", mat);
        //腐蚀
        mat = OpencvUtil.erode(mat, 1);
        Imgcodecs.imwrite("C:/Users/admin/Desktop/cut/test_all_fushi.jpg", mat);
        //边缘检测
        mat = OpencvUtil.carry(mat);
        Imgcodecs.imwrite("C:/Users/admin/Desktop/cut/test_all_bianyuanjiance.jpg", mat);
        //降噪
        mat = OpencvUtil.navieRemoveNoise(mat, 1);
        Imgcodecs.imwrite("C:/Users/admin/Desktop/cut/test_all_jiangzhao.jpg", mat);
        //膨胀
        mat = OpencvUtil.dilate(mat, 1);
        Imgcodecs.imwrite("C:/Users/admin/Desktop/cut/test_all_pengzhang.jpg", mat);

        //轮廓检测,清除小的轮廓部分
        List<MatOfPoint> contours = OpencvUtil.findContours(mat);
        return contours;
    }
}
